﻿using System;
using System.Text.RegularExpressions;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;

namespace YJKRevitStairs.StairsModel.AddSigns
{
	internal class StairSingleSelectionFilter : ISelectionFilter, ISetNowLevel
	{
		public void SetNowLevel(Level input)
		{
			this.nowLevel = input;
		}

		public bool AllowElement(Element elem)
		{
			if (elem is FamilyInstance && this.nowLevel != null && elem.LevelId.IntegerValue == this.nowLevel.Id.IntegerValue)
			{
				Family family = (elem as FamilyInstance).Symbol.Family;
				for (int i = 0; i <= 1; i++)
				{
                    if (elem.Category.Id.IntegerValue == (int)StaticRescours.StairCategories[i] && Regex.IsMatch(family.Name, StaticRescours.FamilyNames[i]))
					{
						return true;
					}
				}
			}
			return false;
		}

		public bool AllowReference(Reference reference, XYZ position)
		{
			return false;
		}

		private Level nowLevel;
	}
}
